package Game_Over;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;

import Game_Start.Win;
import Main.Main;
import Main.Main_Frame;
import Main.makeEastPanel;

public class GameOver extends JFrame implements ActionListener {
	private static final String LinearLayoutMan = null;
	private static GameOver gameover=null;
	public static GameOver getGameOver(int maxScore,int score,long time)
	{
		if(gameover==null) gameover=new GameOver();
		GameOver.setData(maxScore,score,time);
		gameover.setVisible(true);
		return  gameover;
	}
	public static void setData(int maxScore,int score,long time)
	{
		gameover.MAX_SCORE.setText(Integer.toString(maxScore));
		gameover.SCORE.setText(Integer.toString(score));
		gameover.Time.setText(Double.toString(time/1000.0)+"s");
	}
	//private JButton startButton; // 开始游戏按钮
	private JButton highButton;// 历史最高分
	private JButton nowButton;// 本局分数
	private JButton timeButton;// 时间
	private JButton backButton;// 返回主菜单
	private JButton againButton;// 重新开始
	private JLabel MAX_SCORE;
	private JLabel SCORE;
	private JLabel Time;
	public GameOver() {
		
		this.setSize(940, 530);
		this.setResizable(false);
		this.setTitle("贪吃蛇游戏"); // 设置窗口标题
		//this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

		highButton = new JButton("历史最高分:");
		highButton.setBounds(160, 50, 280, 60);
		this.getContentPane().add(highButton);
		Font Fonts = new Font("", Font.BOLD, 42);
		highButton.setFont(Fonts);
		
		
		MAX_SCORE = new JLabel("");//最高
		MAX_SCORE.setBounds(420, 31, 1000, 100);
		this.getContentPane().add(MAX_SCORE);
		Font Fontsa = new Font("",Fonts.BOLD, 42);
		MAX_SCORE.setFont(Fontsa);
		
		SCORE = new JLabel("");//本局
		SCORE.setBounds(420, 113, 1000, 100);
		this.getContentPane().add(SCORE);
		Font Fontsc = new Font("", Font.BOLD,25 );
		SCORE.setFont(Fontsc);
		
		Time = new JLabel("");//时间
		Time.setBounds(420, 173, 1000, 100);
		this.getContentPane().add(Time);
		Font Fontsd = new Font("", Font.BOLD, 20);
		Time.setFont(Fontsd);



		nowButton = new JButton("本局分数:");
		nowButton.setBounds(260, 140, 170, 40);
		this.getContentPane().add(nowButton);
		Font Fonts1 = new Font("", Font.BOLD, 30);
		nowButton.setFont(Fonts1);

		timeButton = new JButton("       时间:");
		timeButton.setBounds(260, 200, 170, 40);
		this.getContentPane().add(timeButton);
		Font Fonts11 = new Font("", Font.BOLD, 30);
		timeButton.setFont(Fonts11);

		againButton = new JButton("重新开始");
		againButton.setBounds(200, 350, 180, 40);
		this.getContentPane().add(againButton);
		Font Fonts1111 = new Font("", Font.BOLD, 35);
		againButton.setFont(Fonts1111);

		backButton = new JButton("返回主菜单");
		backButton.setBounds(480, 350, 230, 40);
		this.getContentPane().add(backButton);
		Font Fonts111 = new Font("", Font.BOLD, 35);
		backButton.setFont(Fonts111);

		highButton.setFocusPainted(false);
		highButton.setContentAreaFilled(false);
		highButton.addActionListener(this);
		highButton.setBorderPainted(false);
		highButton.setFocusPainted(false);
		nowButton.setContentAreaFilled(false);
		nowButton.addActionListener(this);
		nowButton.setBorderPainted(false);
		nowButton.setFocusPainted(false);
		timeButton.setContentAreaFilled(false);
		timeButton.addActionListener(this);
		timeButton.setBorderPainted(false);
		timeButton.setFocusPainted(false);
		backButton.setContentAreaFilled(false);
		backButton.addActionListener(this);
		backButton.setBorderPainted(false);
		backButton.setFocusPainted(false);
		againButton.setContentAreaFilled(false);
		againButton.addActionListener(this);
		againButton.setBorderPainted(false);
		againButton.setFocusPainted(false);

		againButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (e.getSource() == againButton) {
					makeEastPanel.getButton0Start().doClick();
					//System.out.println(getGameOver(0,0,null));
					getGameOver(0,0,0).setVisible(false);// 关闭开始游戏界面
				}
			}
		});
		backButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (e.getSource() == backButton) {
					Main_Frame.Close();
					Win.getFrame().setVisible(true);
					//System.out.println(getGameOver(0,0,null));
					getGameOver(0,0,0).setVisible(false); // 关闭开始游戏界面
				}
			}
		});

		JLabel imgLabel = new JLabel(new ImageIcon("img/over.png"));
		imgLabel.setBounds(0, 0, 937, 510);
		this.getContentPane().add(imgLabel);
		this.setLocationRelativeTo(null);// 居中
		this.setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub

	}

}